<template>
    <div>
         <el-table ref="multipleTableRef" 
            :header-cell-style="{color:'#2A62BC'}"
            :data="tableData"   
            style="width: 100%;" 
            border
            stripe 
            @selection-change="handleSelectionChange">
            <el-table-column   type="selection" width="35" />
            <el-table-column  prop="serial_number" label="序号"  align="center"></el-table-column>
            <el-table-column prop="leave_time" label="请假时间" align="center"></el-table-column>
            <el-table-column prop="end_time" label="结束时间" align="center"></el-table-column>
            <el-table-column prop="student_name" label="学生姓名" align="center"></el-table-column>
            <el-table-column prop="reason_leave" label="请假事由" align="center"></el-table-column>
            <el-table-column prop="approval_status" label="审核状态" align="center"></el-table-column>
            <el-table-column label="操作" width="150" align="center" >
                        <template #default="scope">
                            <el-row class="right-btn">
                            <el-tooltip content="通过审核" placement="bottom" effect="light">
                                <el-button   @click="approved(scope.row)">
                                    <i class="iconfont icon-duigou_kuai "></i>
                                </el-button>
                            </el-tooltip>
                            <el-tooltip content="拒绝审查" placement="bottom" effect="light">
                                <el-button    @click="rejectApproved(scope.row)">
                                    <i class="iconfont icon-cuocha_kuai red"></i>
                                </el-button>
                            </el-tooltip>
                            </el-row>
                            <!-- </el-button-group> -->
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
            <div class="pagination">
                    <el-pagination
                    :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :page-sizes="[5, 10, 15, 20]"
                       size="small"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageTotal"
                        @size-change="handleSizeChange"
                        @current-change="handlePageChange"/>
                </div>
              
                
        </div>
    </template>
    
    <script setup>
    import { ref, reactive } from 'vue';
    import { ElMessage, ElMessageBox } from 'element-plus';
    import { Delete, Edit, Search, CaretBottom } from '@element-plus/icons-vue';
    import { getStuLeave } from '../../../api/teaching' ;
         
    //分页字体
    const small = ref(true)
    // const size = ref<'default' | 'large' | 'small'>('default')
    
    //分页数据
    const query = reactive({
        pageIndex: 1,
        pageSize: 5,
    });
    //表格数据
    const tableData = ref();
    //总页数
    const pageTotal = ref(0);
    const multipleTableRef = ref()
    const state = reactive({
        multipleSelection:[]
    })
    
    // 获取表格数据  分页是数据截取  后台结合一起后  直接返回分页的后的数据
    const getData = () => {
        getStuLeave({pageCurrent:query.pageIndex,pageSize:query.pageSize}).then(res=>{
            console.log(res,"---res---")
            // tableData.value = res.data.
            let start  = (query.pageIndex-1)*query.pageSize;//开始位置
            let end =query.pageIndex*query.pageSize  ;//结束位置 数组的截取的时候 [start,end) suo所以不用-1
            tableData.value = res.data.slice(start,end);
            // tableData.value = res.data;
            pageTotal.value = res.data.length
        })
       
        
    };
    getData();
    //多选框权限
    const handleSelectionChange = (val) => {
      state.multipleSelection = val
    }
    // 分页导航
    const handleSizeChange = (val) => {
      // console.log(`${val} items per page`)
      query.pageSize = val;
      getData()
    }
    const handlePageChange = (val) => {
        query.pageIndex = val;
        getData()
    };
    
    //通过审批
    const approved=(row)=>{
        ElMessageBox.confirm(
            '是否通过审批',
            '提示',
            {
            confirmButtonText: '确定',
            cancelButtonText: '关闭',
            }
        )
    // .then(() => {
    //   ElMessage({
    //     type: 'success',
    //     message: 'Delete completed',
    //   })
    // })
    // .catch(() => {
    //   ElMessage({
    //     type: 'info',
    //     message: 'Delete canceled',
    //   })
    // })

    }
    //拒绝审批
    const rejectApproved=(row)=>{
        ElMessageBox.confirm(
            '是否拒绝审批',
            '提示',
            {
            confirmButtonText: '确定',
            cancelButtonText: '关闭',
            }
        )
    }

</script >
<style lang="less" scoped>
    .handle-box {
        margin-bottom: 20px;   
        .handle-btn{
            margin-left: 8px;
        }    
    }
    .handle-input {
        width:200px;
       padding: 6px;
    }
    .label{
       display: inline-block;
       max-width:100%;
       margin: 5px;
       font-weight: 100; 
       color: #676a6c;
       
    }
    .top-btn{
        float: right;
        .el-button{
            margin-left: 5px;
        }
    }
    .right-btn{
         justify-content:center;
        .el-button{
            height: 22px;
            // width: 60px;
            margin-right: 2px;
            padding: 1px 5px;
        }
    }
    
    
    </style>